import { FC } from 'react';
import { Route, Redirect, useLocation } from 'react-router-dom';

interface IPrivateRoute{ path: string }

const PrivateRoute:FC<IPrivateRoute> = ({ children, path }) => {
  const auth = 1;
  const location = useLocation();
  return (
    <Route path={path}>
      {auth ? (children) : (
        <Redirect
          to={{
            pathname: '/login',
            state: { from: location },
          }}
        />
      )}
    </Route>
  );
};
export default PrivateRoute;
